<?php
	class Monetization extends Model_Abstract{
		
		public function add($name, $note, $html, $secretKey, $appId){
			try{
				$sql = 'insert into monetizations set name=?, note=?, html=?, secret_key=?, app_id=?';
				$result = $this->_connection->execute($sql, array($name, $note, $html, $secretKey, $appId));
				return $result;
			}catch (Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function update($name, $note, $html, $secretKey, $appId, $id){
			try{
				$sql = 'update monetizations set name=?, note=?, html=?, secret_key=?, app_id=? where id=?';
				$result = $this->_connection->execute($sql, array($name, $note, $html, $secretKey, $appId, $id));
				return $result;
			}catch (Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function delete($id){
			try{
				$sql = 'delete from monetizations where id=?';
				$result = $this->_connection->execute($sql, array($id));
				return $result;
			}catch (Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function getMonetizationById($id){
			try{
				$sql = 'select * from monetizations where id=?';
				$result = $this->_connection->query($sql, array($id));
				if($result)
					return $result[0];
				else
					return false;
			}catch (Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function getAllMonetizations(){
			try{
				$sql = 'select * from monetizations';
				$result = $this->_connection->query($sql);
				if($result)
					return $result;
				else
					return false;
			}catch (Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function getAllMonetizationsAsList(){
			try{
				$sql = 'select id, name, note from monetizations';
				$result = $this->_connection->query($sql);
				if($result)
					return $result;
				return false;
			}catch (Exception $e){
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
	}